//
//  PropertyCell.m
//  Trackit
//
//  Created by yaodaobin on 2017/4/17.
//  Copyright © 2017年 yaodaobin. All rights reserved.
//

#import "PropertyCell.h"

@implementation PropertyCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [self initUI];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initUI];
    }
    return self;
}

- (void)initUI {
    self.titleLabel = [[UILabel alloc] init];
    self.titleLabel.font = [UIFont systemFontOfSize:14];
    self.titleLabel.textColor = [UIColor grayColor];
    [self.contentView addSubview:self.titleLabel];
    
    self.textField = [[UITextField alloc] init];
    self.textField.delegate = self;
    self.textField.font = [UIFont systemFontOfSize:14];
    self.textField.textColor = [UIColor blackColor];
    self.textField.placeholder = @"请输入";
    [self.contentView addSubview:self.textField];
    
    kWeakSelf
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.offset(20);
        make.centerY.offset(0);
    }];
    [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.offset(0);
        make.leading.equalTo(weakSelf.titleLabel.mas_trailing).offset(20);
        make.trailing.equalTo(weakSelf.mas_trailing).offset(-20);
    }];
    
    //设置label1的content hugging 为1000
    [self.titleLabel setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    
    //设置label1的content compression 为1000
    [self.titleLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    
    //设置右边的label2的content hugging 为1000
    [self.textField setContentHuggingPriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];
    
    //设置右边的label2的content compression 为250
    [self.textField setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh forAxis:UILayoutConstraintAxisHorizontal];

}

- (void)setItem:(PropertyItem *)item {
    _item = item;
    if ([item.inputTitle isEqualToString:@"确权证号"]) {
        self.textField.placeholder = @"请输入，没有可不填";
    } else {
        self.textField.placeholder = @"请输入";
    }
    self.titleLabel.text = item.inputTitle;
    self.textField.keyboardType = [self getKeyboard:item.keyboard];
}

- (UIKeyboardType)getKeyboard:(NSInteger)index {
    UIKeyboardType type = UIKeyboardTypeDefault;
    if (index == 1) {
        type = UIKeyboardTypeNumberPad;
    } else if (index == 2) {
        type = UIKeyboardTypeDecimalPad;
    }
    return type;
}

@end
